#!/bin/bash

cd $(dirname $0)
export LANG=

lines=$(svn st ../trunk|wc -l)
if [ "$lines" != "0" ]
then
	echo "Uncommited changes in trunk!"
	echo "You should commit all changes first before creating a new tag"
	exit 1
fi

version=$(grep "<em:version>" ../trunk/install.rdf | sed \
 -e 's/^[[:blank:]]*//' \
 -e 's/[[:blank:]]*$//' \
 -e 's!^.*<em:version>!!'  \
 -e 's!</em:version>.*$!!')
if [ -e "./v$version" ]
then
	echo "There is already a tag named v$version!"
	echo "You should change the version in install.rdf"
	exit 1
fi

rm -rf update update.zip

echo "Create tag for version $version..."

svn copy ../trunk ./v$version
svn commit ./v$version -m "Created v$version"

echo "Export files..."

svn export ./v$version update

echo "Create XPI..."

cd update
zip ../update.zip -r *
cd ..

rm -rf update
mv update.zip "HideBookmarksBar $version.xpi"

echo "Upload file..."
python googlecode_upload.py -s "HideBookmarksBar $version" -p hide-bookmarksbar -l Type-Package,OpSys-All,Featured "HideBookmarksBar $version.xpi" && \
rm "HideBookmarksBar $version.xpi"
echo "Done."

